/*
 * Copyright (c) 2000-2018, 达梦数据库有限公司.
 * All rights reserved.
 */
package dm

import (
	"container/list"
	"io"
)

type Dm_build_1214 struct {
	dm_build_1215 *list.List
	dm_build_1216 *dm_build_1268
	dm_build_1217 int
}

func Dm_build_1218() *Dm_build_1214 {
	return &Dm_build_1214{
		dm_build_1215: list.New(),
		dm_build_1217: 0,
	}
}

func (dm_build_1220 *Dm_build_1214) Dm_build_1219() int {
	return dm_build_1220.dm_build_1217
}

func (dm_build_1222 *Dm_build_1214) Dm_build_1221(dm_build_1223 *Dm_build_1292, dm_build_1224 int) int {
	var dm_build_1225 = 0
	var dm_build_1226 = 0
	for dm_build_1225 < dm_build_1224 && dm_build_1222.dm_build_1216 != nil {
		dm_build_1226 = dm_build_1222.dm_build_1216.dm_build_1276(dm_build_1223, dm_build_1224-dm_build_1225)
		if dm_build_1222.dm_build_1216.dm_build_1271 == 0 {
			dm_build_1222.dm_build_1258()
		}
		dm_build_1225 += dm_build_1226
		dm_build_1222.dm_build_1217 -= dm_build_1226
	}
	return dm_build_1225
}

func (dm_build_1228 *Dm_build_1214) Dm_build_1227(dm_build_1229 []byte, dm_build_1230 int, dm_build_1231 int) int {
	var dm_build_1232 = 0
	var dm_build_1233 = 0
	for dm_build_1232 < dm_build_1231 && dm_build_1228.dm_build_1216 != nil {
		dm_build_1233 = dm_build_1228.dm_build_1216.dm_build_1280(dm_build_1229, dm_build_1230, dm_build_1231-dm_build_1232)
		if dm_build_1228.dm_build_1216.dm_build_1271 == 0 {
			dm_build_1228.dm_build_1258()
		}
		dm_build_1232 += dm_build_1233
		dm_build_1228.dm_build_1217 -= dm_build_1233
		dm_build_1230 += dm_build_1233
	}
	return dm_build_1232
}

func (dm_build_1235 *Dm_build_1214) Dm_build_1234(dm_build_1236 io.Writer, dm_build_1237 int) int {
	var dm_build_1238 = 0
	var dm_build_1239 = 0
	for dm_build_1238 < dm_build_1237 && dm_build_1235.dm_build_1216 != nil {
		dm_build_1239 = dm_build_1235.dm_build_1216.dm_build_1285(dm_build_1236, dm_build_1237-dm_build_1238)
		if dm_build_1235.dm_build_1216.dm_build_1271 == 0 {
			dm_build_1235.dm_build_1258()
		}
		dm_build_1238 += dm_build_1239
		dm_build_1235.dm_build_1217 -= dm_build_1239
	}
	return dm_build_1238
}

func (dm_build_1241 *Dm_build_1214) Dm_build_1240(dm_build_1242 []byte, dm_build_1243 int, dm_build_1244 int) {
	if dm_build_1244 == 0 {
		return
	}
	var dm_build_1245 = dm_build_1272(dm_build_1242, dm_build_1243, dm_build_1244)
	if dm_build_1241.dm_build_1216 == nil {
		dm_build_1241.dm_build_1216 = dm_build_1245
	} else {
		dm_build_1241.dm_build_1215.PushBack(dm_build_1245)
	}
	dm_build_1241.dm_build_1217 += dm_build_1244
}

func (dm_build_1247 *Dm_build_1214) dm_build_1246(dm_build_1248 int) byte {
	var dm_build_1249 = dm_build_1248
	var dm_build_1250 = dm_build_1247.dm_build_1216
	for dm_build_1249 > 0 && dm_build_1250 != nil {
		if dm_build_1250.dm_build_1271 == 0 {
			continue
		}
		if dm_build_1249 > dm_build_1250.dm_build_1271-1 {
			dm_build_1249 -= dm_build_1250.dm_build_1271
			dm_build_1250 = dm_build_1247.dm_build_1215.Front().Value.(*dm_build_1268)
		} else {
			break
		}
	}
	return dm_build_1250.dm_build_1289(dm_build_1249)
}
func (dm_build_1252 *Dm_build_1214) Dm_build_1251(dm_build_1253 *Dm_build_1214) {
	if dm_build_1253.dm_build_1217 == 0 {
		return
	}
	var dm_build_1254 = dm_build_1253.dm_build_1216
	for dm_build_1254 != nil {
		dm_build_1252.dm_build_1255(dm_build_1254)
		dm_build_1253.dm_build_1258()
		dm_build_1254 = dm_build_1253.dm_build_1216
	}
	dm_build_1253.dm_build_1217 = 0
}
func (dm_build_1256 *Dm_build_1214) dm_build_1255(dm_build_1257 *dm_build_1268) {
	if dm_build_1257.dm_build_1271 == 0 {
		return
	}
	if dm_build_1256.dm_build_1216 == nil {
		dm_build_1256.dm_build_1216 = dm_build_1257
	} else {
		dm_build_1256.dm_build_1215.PushBack(dm_build_1257)
	}
	dm_build_1256.dm_build_1217 += dm_build_1257.dm_build_1271
}

func (dm_build_1259 *Dm_build_1214) dm_build_1258() {
	var dm_build_1260 = dm_build_1259.dm_build_1215.Front()
	if dm_build_1260 == nil {
		dm_build_1259.dm_build_1216 = nil
	} else {
		dm_build_1259.dm_build_1216 = dm_build_1260.Value.(*dm_build_1268)
		dm_build_1259.dm_build_1215.Remove(dm_build_1260)
	}
}

func (dm_build_1262 *Dm_build_1214) Dm_build_1261() []byte {
	var dm_build_1263 = make([]byte, dm_build_1262.dm_build_1217)
	var dm_build_1264 = dm_build_1262.dm_build_1216
	var dm_build_1265 = 0
	var dm_build_1266 = len(dm_build_1263)
	var dm_build_1267 = 0
	for dm_build_1264 != nil {
		if dm_build_1264.dm_build_1271 > 0 {
			if dm_build_1266 > dm_build_1264.dm_build_1271 {
				dm_build_1267 = dm_build_1264.dm_build_1271
			} else {
				dm_build_1267 = dm_build_1266
			}
			copy(dm_build_1263[dm_build_1265:dm_build_1265+dm_build_1267], dm_build_1264.dm_build_1269[dm_build_1264.dm_build_1270:dm_build_1264.dm_build_1270+dm_build_1267])
			dm_build_1265 += dm_build_1267
			dm_build_1266 -= dm_build_1267
		}
		if dm_build_1262.dm_build_1215.Front() == nil {
			dm_build_1264 = nil
		} else {
			dm_build_1264 = dm_build_1262.dm_build_1215.Front().Value.(*dm_build_1268)
		}
	}
	return dm_build_1263
}

type dm_build_1268 struct {
	dm_build_1269 []byte
	dm_build_1270 int
	dm_build_1271 int
}

func dm_build_1272(dm_build_1273 []byte, dm_build_1274 int, dm_build_1275 int) *dm_build_1268 {
	return &dm_build_1268{
		dm_build_1273,
		dm_build_1274,
		dm_build_1275,
	}
}

func (dm_build_1277 *dm_build_1268) dm_build_1276(dm_build_1278 *Dm_build_1292, dm_build_1279 int) int {
	if dm_build_1277.dm_build_1271 <= dm_build_1279 {
		dm_build_1279 = dm_build_1277.dm_build_1271
	}
	dm_build_1278.Dm_build_1375(dm_build_1277.dm_build_1269[dm_build_1277.dm_build_1270 : dm_build_1277.dm_build_1270+dm_build_1279])
	dm_build_1277.dm_build_1270 += dm_build_1279
	dm_build_1277.dm_build_1271 -= dm_build_1279
	return dm_build_1279
}

func (dm_build_1281 *dm_build_1268) dm_build_1280(dm_build_1282 []byte, dm_build_1283 int, dm_build_1284 int) int {
	if dm_build_1281.dm_build_1271 <= dm_build_1284 {
		dm_build_1284 = dm_build_1281.dm_build_1271
	}
	copy(dm_build_1282[dm_build_1283:dm_build_1283+dm_build_1284], dm_build_1281.dm_build_1269[dm_build_1281.dm_build_1270:dm_build_1281.dm_build_1270+dm_build_1284])
	dm_build_1281.dm_build_1270 += dm_build_1284
	dm_build_1281.dm_build_1271 -= dm_build_1284
	return dm_build_1284
}

func (dm_build_1286 *dm_build_1268) dm_build_1285(dm_build_1287 io.Writer, dm_build_1288 int) int {
	if dm_build_1286.dm_build_1271 <= dm_build_1288 {
		dm_build_1288 = dm_build_1286.dm_build_1271
	}
	dm_build_1287.Write(dm_build_1286.dm_build_1269[dm_build_1286.dm_build_1270 : dm_build_1286.dm_build_1270+dm_build_1288])
	dm_build_1286.dm_build_1270 += dm_build_1288
	dm_build_1286.dm_build_1271 -= dm_build_1288
	return dm_build_1288
}
func (dm_build_1290 *dm_build_1268) dm_build_1289(dm_build_1291 int) byte {
	return dm_build_1290.dm_build_1269[dm_build_1290.dm_build_1270+dm_build_1291]
}
